Skip to content

feat(output): add configurable time_format with locale encoding fix#385

Merged
sudo-tee merged 1 commit into
sudo-tee:mainfrom
CnsMaple:fix/time-format-config
May 23, 2026
Merged

feat(output): add configurable time_format with locale encoding fix#385
sudo-tee merged 1 commit into
sudo-tee:mainfrom
CnsMaple:fix/time-format-config

Conversation

@CnsMaple
Copy link
Copy Markdown
Contributor

Summary

Add a new ui.output.time_format config option to allow users to customize timestamp display format in message headers. Also fixes a locale encoding issue on Chinese Windows where os.date('%b') returns GBK-encoded characters (e.g. 5月 → displayed as 5<d4><c2>).

Changes

lua/opencode/config.lua

  • Added time_format = nil default under ui.output

lua/opencode/types.lua

  • Added ---@field time_format string|nil to OpencodeUIOutputConfig

lua/opencode/util.lua

  • If time_format is set, uses it directly via os.date(time_format, timestamp)
  • When nil (default), wraps locale-sensitive os.date('%X', ...) and os.date('%b', ...) calls in os.setlocale('C', 'time')/restore pairs to prevent non-UTF-8 output

tests/unit/util_spec.lua

  • Updated test helpers to use C locale for comparison, matching the new behavior

Usage

require('opencode').setup({
  ui = {
    output = {
      time_format = '%m/%d %H:%M',  -- e.g. "05/21 19:13"
    },
  },
})

When unset (nil), behavior matches the original format but with the encoding bug fixed.

@sudo-tee
Copy link
Copy Markdown
Owner

Thanks for the PR

@sudo-tee sudo-tee merged commit 99f26ff into sudo-tee:main May 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants